import { ApiCall } from "tsrpc";
import { ReqMap, ResMap } from "../../../shared/master/word/PtlMap";
import { player } from "../../../model/fight/body/player";
import { template } from "../../../shared/master/MsgAction";

export default async function (call: ApiCall<ReqMap, ResMap>) {
    call.succ({})
    let user = call.req._player as player;
    let mapArray: number[][] = [];
    let _cell = user.getPosition();
    let _word = _cell.getWord();

    for (let y = _cell.y + 5; y >= _cell.y - 5; y--) {
        let row: number[] = [];
        for (let x = _cell.x - 5; x <= _cell.x + 5; x++) {
            const item_cell = _word.getCell(x, y);
            if (y === _cell.y && x === _cell.x) {
                row.push(2); // 单位所在格子
                continue;
            }
            if (item_cell) {
                if (item_cell.get_giftBox()) {
                    // 有宝箱🎁
                    row.push(3); // 单位所在格子
                } else if (item_cell.get_battleSize()) {
                    // 有宝箱正在战斗
                    row.push(4); // 单位所在格子
                }else if(item_cell.get_water()){
                     // 有水
                     row.push(5); // 单位所在格子
                }
                else {
                    row.push(1); // 单位所在格子
                }
            } else {
                row.push(0); // 1 表示有格子，0 表示没有格子
            }
        }
        mapArray.push(row);
    }
    user.sendMsg(template.wordMap, { msg:call.req.msg,list: mapArray })
}